﻿TestResult = function (testName) {
    this.testName = testName;
    this.success = true;
    this.errorMessage = "";
};

TestFixtureResult = function (fixtureName) {
    this.fixtureName = fixtureName;
    this.results = [];
};

TestFixtureResult.prototype.AddTestResult = function (testResult) {
    this.results.push(testResult);
};


TestFixture = function () {
    this.Name = "TestFixture";
};


TestFixture.prototype.Assert = function (expected, actual) {
    if (expected != actual)
        throw "Expected: " + expected + ", Actual: " + actual;
};

TestFixture.prototype.Execute = function () {
    var testFixtureResult = new TestFixtureResult(this.Name);

    for (var p in this) {
        if (typeof (this[p]) != "function")
            continue;

        if (p.toLowerCase().indexOf("test") == -1)
            continue;

        var testResult = new TestResult(p);

        try {
            this[p]();
            testResult.success = true;
        }
        catch (ex) {
            testResult.success = false;
            testResult.errorMessage = ex.toString();
        }

        testFixtureResult.AddTestResult(testResult);
    }

    return testFixtureResult;
};

SimpleTestFixture = function () {
    this.Name = "Simple Test Fixture";
};

SimpleTestFixture.prototype = new TestFixture();

SimpleTestFixture.prototype.TestSimpleBools = function () {
    var a = true;
    var b = true;
    this.Assert(a, b);
};

SimpleTestFixture.prototype.TestSimpleFailure = function () {
    var a = true;
    var b = false;
    this.Assert(a, b);
};

//var tf = new SimpleTestFixture();
//var result = tf.Execute();
//PrintResults(result);